package com.example.charpter05;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import util.DateUtil;

public class ButtonClickActivity extends AppCompatActivity {

    private TextView viewById;
    private Button viewById1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_button_click);

        viewById = findViewById(R.id.tv_result);
        TextView tv_result = viewById;
        viewById1 = findViewById(R.id.btn_click_single);
        Button btn_click_single = viewById1;
        btn_click_single.setOnClickListener(new MyOnClickListener(tv_result));



    }

    static class MyOnClickListener implements View.OnClickListener{

        private final TextView tv_result;

        public MyOnClickListener(TextView tv_result) {
            this.tv_result=tv_result;
        }

        @Override
        public  void onClick(View v){
            String desc = String.format("%s 您点击了按钮:  %s", DateUtil.getNowTime(),((Button)v).getText());
            tv_result.setText(desc);

        }


    }



}